
function on_check(obj,item){
  var index=$(obj).parent('#checkboxBtn').nextAll('a').find('#itemId').text();
  if($(obj).get(0).checked == true){
    ids.push(index);
    if(ids.length == totalRow){
      $('#allCheck').prop('checked',true);
    }
  }else{
    ids.splice( ids.indexOf(index), 1 );
    if(ids.length != totalRow){
      $('#allCheck').prop('checked',false);
    }
  }
  console.log(ids);
}
function on_radio(obj,item){
   var index=$(obj).parent('#radioBtn').nextAll('a').find('#itemId').text();
   console.log(index);
   var indexSn=$(obj).parent('#radioBtn').nextAll('a').find('#itemId').next().text();

   // var indexSn=$(obj).parent('#radioBtn').nextAll('a').find('#itemSn').text();
   console.log(indexSn);
  
  if(item=='business'){
    businessDelArr[0]=index;
    $(".business-edit-btn").attr("href","/h5/business/add?id="+businessDelArr);
  }else if(item=='app'){
    appDelArr[0]=index;
    $(".app-edit-btn").attr("href","/h5/app/add?id="+appDelArr);
  }else if(item=='protocol'){
    protocolDelArr[0]=index;
    $(".protocol-edit-btn").attr("href","/h5/protocol/add?id="+protocolDelArr);
  }else{
    
     deviceDelArr[0]=index;
     deviceDelArr[1]=indexSn;
     console.log(deviceDelArr[0]);
     console.log(deviceDelArr[1]);
    $(".device-edit-btn").attr("href","/h5/device/add?userId="+deviceDelArr[0]+"&deviceSn="+deviceDelArr[1]);
  } 
}

function all_check(obj){
  if($(obj).get(0).checked == true){
    ids=[];
    $('[type="checkbox"]').prop('checked',true); 
    $('.business-list li').each(function(){
      ids.push($(this).find('#itemId').text());
    })         
  }else{
    $('[type="checkbox"]').prop('checked',false);
    ids=[];
  }
}
function business_del(){
  ids=[],businessDelArr=[];
  $('#business-content').addClass('mb30');
  $('#footerDelBusiness').css('display','flex');
  $('.business-list .item-content #checkboxBtn').css('display','flex'); 
  $('[type="radio"]').get(0).checked=false;
  $('[type="radio"]').removeAttr('checked');
  $('[type="checkbox"]').get(0).checked=false;
  $('[type="checkbox"]').removeAttr("checked");
  $('#footerEditBusiness').css('display','none');
  $('.business-list .item-content #radioBtn').css('display','none');
}
function business_edit(){
  ids=[],businessDelArr=[];
  $('#business-content').addClass('mb30');
  $('#footerEditBusiness').css('display','flex');
  $('.business-list .item-content #radioBtn').css('display','flex');
  $('[type="radio"]').get(0).checked=false;
  $('[type="radio"]').removeAttr('checked');
  $('[type="checkbox"]').get(0).checked=false;
  $('[type="checkbox"]').removeAttr("checked"); 
  $('#footerDelBusiness').css('display','none');
  $('.business-list .item-content #checkboxBtn').css('display','none');
}

function app_del(){
  ids=[],appDelArr=[];
  $('#app-content').addClass('mb30');
  $('#footerDelApp').css('display','flex');
  $('.app-list .item-content #checkboxBtn').css('display','flex');
  $('[type="radio"]').get(0).checked=false;
  $('[type="radio"]').removeAttr('checked');
  $('[type="checkbox"]').get(0).checked=false;
  $('[type="checkbox"]').removeAttr("checked");
  $('#footerEditApp').css('display','none');
  $('.app-list .item-content #radioBtn').css('display','none');
}

function app_edit(){
  ids=[],appDelArr=[];
  $('#app-content').addClass('mb30');
  $('#footerEditApp').css('display','flex');
  $('.app-list .item-content #radioBtn').css('display','flex');
  $('[type="radio"]').get(0).checked=false;
  $('[type="radio"]').removeAttr('checked');
  $('[type="checkbox"]').get(0).checked=false;
  $('[type="checkbox"]').removeAttr("checked"); 
  $('#footerDelApp').css('display','none');
  $('.app-list .item-content #checkboxBtn').css('display','none');
}

// function urlTest(){
//      var urlTest = $("#app-url").val();
//      $.ajax({
//      url:"/app/testAddress",
//      type:"POST",
//      data:{'url':urlTest},
//      dataType:"json",
//      success:function(data){   //获取该网址是否可用的返回码
//         console.log(data);
//           if(data.statusCode=="200"){
//              $.toast(data.message);
//           }else{
//              $.toast(data.message);
//           }
//       }
//    });
// }
function addAppItems(pageCurrent, pageSize,appname,btn) {
  console.log('appname='+appname);
  $.ajax({
    url:'/app/list',
    type:'post',
    data:{pageCurrent:pageCurrent, pageSize:pageSize,name:appname},
    dataType:'json',
    success:function(json){
      totalRow=json.totalRow;
      if(totalRow<11){
        $('.infinite-scroll-preloader').remove();
      }
      $('.app-list').setList(json,'app','推送地址：',btn,pageCurrent,'list-container app-list');
    }

  })
}
function addBusinessItems(pageCurrent, pageSize,businessname,btn) {
  $.ajax({
    url:'/business/list',
    type:'post',
    data:{pageCurrent:pageCurrent, pageSize:pageSize,name:businessname},
    dataType:'json',
    success:function(json){
      totalRow=json.totalRow;
      if(totalRow<11){
        $('.infinite-scroll-preloader').remove();
      }
      $('.business-list').setList(json,'business','Key：',btn,pageCurrent,'list-container business-list');
    }
  })
}